package org.jeecg.modules.mall.job;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.show.api.ShowApiRequest;
import com.taobao.api.internal.util.TaobaoUtils;
import org.jeecg.common.util.UUIDGenerator;
import org.jeecg.modules.mall.entity.Pagebean;
import org.jeecg.modules.mall.entity.TbNewChannel;
import org.jeecg.modules.mall.entity.TbNewsContent;
import org.jeecg.modules.mall.entity.Tb_news2;
import org.jeecg.modules.mall.service.ITbNewChannelService;
import org.jeecg.modules.mall.service.ITbNewsContentService;
import org.jeecg.modules.mall.service.ITb_news2Service;
import org.jeecg.modules.mall.util.TaoBaoUtil;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class GrabNewsTask implements Job {


    @Autowired
    private ITb_news2Service tb_news2Service;

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        List<Tb_news2> tb_news2List = NewsUtils.getNewsData();
         if(null!=tb_news2List){
             for (Tb_news2 tb_news2 : tb_news2List) {
                 String uniquekey=  tb_news2.getUniquekey();
                 QueryWrapper queryWrapper=new QueryWrapper();
                 queryWrapper.eq("uniquekey",uniquekey);
                 Tb_news2 tb_news21= tb_news2Service.getOne(queryWrapper);
                 if(null==tb_news21){
                     tb_news2.setId(UUIDGenerator.generate());
                     tb_news2Service.save(tb_news2);
                 }
             }
         }
    }

}
